package com.dongdongshop.service.imp;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.TbUserScoreDetailMapper;
import com.dongdongshop.pojo.TbUserScoreDetail;
import com.dongdongshop.pojo.TbUserScoreUse;
import com.dongdongshop.service.ScoreDetailService;
import com.dongdongshop.service.ScoreUseService;

import javax.annotation.Resource;

@Service
@org.springframework.stereotype.Service
public class ScoreDetailServiceImpl implements ScoreDetailService {
    @Resource
    private ScoreUseService scoreUseService;

    @Resource
    private TbUserScoreDetailMapper tbUserScoreDetailMapper;

    @Override
    public void addinfo(TbUserScoreDetail tbUserScoreDetail) {
        if (tbUserScoreDetail.getScore() >0){
            tbUserScoreDetail.setNote("新增积分");
        }else {
            tbUserScoreDetail.setNote("使用积分");
        }
        tbUserScoreDetailMapper.insertSelective(tbUserScoreDetail);

        /*可用积分表添加*/
        TbUserScoreUse scoreUse = new TbUserScoreUse();
        scoreUse.setSocreId(tbUserScoreDetail.getDetailId());
        scoreUse.setUserId(tbUserScoreDetail.getUserId());
        scoreUse.setUseScore(tbUserScoreDetail.getScore());
        scoreUse.setAddtime(tbUserScoreDetail.getAddtime());
        scoreUse.setClosetime(tbUserScoreDetail.getClosetime());
        scoreUseService.addinfo(scoreUse);
    }

    @Override
    public void toAdd(TbUserScoreDetail tbUserScoreDetail) {
        tbUserScoreDetailMapper.insertSelective(tbUserScoreDetail);
    }
}
